// The purpose of this header file is to display the Siosis Logo in a pre-built Gl window.
// Simply call 'Siosis_Logo_v1(void)'. Function returns 0 if successful.

#ifndef Kirinki
#define Kirinki

#include "siosis_pause.h"

class shard
{
public:
	shard() {}
	
	shard(float x, float y, float z, float height, float width, float speed, float rotation, int texture): 
		itsX(x),
		itsY(y),
		itsZ(z),
		itsHeight(height),
		itsWidth(width),
		itsRotation(rotation),
		itsTexture(texture),
		itsSpeed(speed) {}
		
	~shard() {}

	// Accessor functions: -
	float	GetX() const { return itsX; }
	float	GetY() const { return itsY; }
	float	GetZ() const { return itsZ; }
	float	GetHeight() const { return itsHeight; }
	float	GetWidth() const { return itsWidth; }
	float	GetSpeed() const { return itsSpeed; }
	float	GetRotation() const { return itsRotation; }
	int		GetTexture() const { return itsTexture; }
	void	SetX(float x) { itsX = x; }
	void	SetY(float y) { itsY = y; }
	void	SetZ(float z) { itsZ = z; }
	void	SetHeight(float height) { itsHeight = height; }
	void	SetWidth(float width) { itsWidth = width; }
	void	SetSpeed(float speed) { itsSpeed = speed; }
	void	SetRotation(float rotation) { itsRotation = rotation; }
	void	SetTexture(int texture) { itsTexture = texture; }
	// Methods: -
	void Draw();
	void Rot() { itsRotation++; }

private:
	float	itsX;
	float	itsY;
	float	itsZ;
	float	itsHeight;
	float	itsWidth;
	float	itsSpeed;
	float	itsRotation;
	int		itsTexture;
};

void shard::Draw()
{
	//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glEnable(GL_TEXTURE_2D);

	
	if(itsTexture == 0) glBindTexture(GL_TEXTURE_2D, g_Texture[0]);
	if(itsTexture == 1) glBindTexture(GL_TEXTURE_2D, g_Texture[1]);
	if(itsTexture == 2) glBindTexture(GL_TEXTURE_2D, g_Texture[2]);
	if(itsTexture == 3) glBindTexture(GL_TEXTURE_2D, g_Texture[3]);
	

	glTranslatef(itsX,itsY,itsZ);

	glRotatef((float)(itsRotation * itsSpeed), 0.0f, 1.0f, 0.0f);
	
	glColor3f(1.0f,1.0f,1.0f);
	
	glBegin(GL_QUADS);
	
		// Top right.
		//glColor3f(0.0f,0.0f,1.0f);
		glTexCoord2f(1.0f,0.0f); glVertex3f(0.0f + (itsWidth/2), 0.0f - (itsHeight/2), 0.0f);	
		// Bottom right.
		//glColor3f(1.0f,1.0f,0.0f);
		glTexCoord2f(1.0f,1.0f); glVertex3f(0.0f + (itsWidth/2), 0.0f + (itsHeight/2), 0.0f);
		// Bottom left.
		//glColor3f(0.5f,1.0f,0.0f);
		glTexCoord2f(0.0f,1.0f); glVertex3f(0.0f - (itsWidth/2), 0.0f + (itsHeight/2), 0.0f);
		// Top left.
		//glColor3f(1.0f,0.0f,0.0f);
		glTexCoord2f(0.0f,0.0f); glVertex3f(0.0f - (itsWidth/2), 0.0f - (itsHeight/2), 0.0f);



	glEnd();
	
	//SwapBuffers(hDC);	// Display what we've drawn!
}


int Siosis_v1()
{
	
	CreateTexture(g_Texture, "Data/Images/Siosisv1.bmp", 0); // Load "matrix.bmp" into openGL as a texture.
	
	music=BASS_StreamCreateFile(FALSE,"Data/Sounds/Siosis_Theme1.mp3",0,0,BASS_MUSIC_3D);	// Load A Song								***
	BASS_Start();												// Start The Engine											***
	BASS_StreamPlay(music,FALSE,BASS_SAMPLE_3D);

#define MAX_SHARDS 4

	shard shards[MAX_SHARDS];
	srand(GetTickCount());	// Seed for random number.

		shards[0].SetHeight(0.4f);
		shards[0].SetWidth(0.4f);
		shards[0].SetSpeed(1.0f);	// Random.
		shards[0].SetRotation(1.0f);
		shards[0].SetX(0.0f);
		shards[0].SetY(-0.55f);
		shards[0].SetZ(-4.0f);
		shards[0].SetTexture(0); 

		shards[1].SetHeight(0.4f);
		shards[1].SetWidth(0.4f);
		shards[1].SetSpeed(0.5f);	// Random.
		shards[1].SetRotation(1.0f);
		shards[1].SetX(0.0f);
		shards[1].SetY(0.55f);
		shards[1].SetZ(-4.0f);
		shards[1].SetTexture(0); 

		shards[2].SetHeight(0.4f);
		shards[2].SetWidth(0.4f);
		shards[2].SetSpeed(1.0f);	// Random.
		shards[2].SetRotation(1.0f);
		shards[2].SetX(-0.7f);
		shards[2].SetY(0.0f);
		shards[2].SetZ(-4.0f);
		shards[2].SetTexture(0); 

		shards[3].SetHeight(0.4f);
		shards[3].SetWidth(0.4f);
		shards[3].SetSpeed(0.5f);	// Random.
		shards[3].SetRotation(1.0f);
		shards[3].SetX(0.7f);
		shards[3].SetY(0.0f);
		shards[3].SetZ(-4.0f);
		shards[3].SetTexture(0); 

		LoopPause(14);	// Runs for 14 seconds.
	while(LoopPause())
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear screen and depth buffer.
		glLoadIdentity();
		
		glEnable(GL_TEXTURE_2D);
		glColor3f(1.0f,1.0f,1.0f);
		
		glBindTexture(GL_TEXTURE_2D, g_Texture[0]);	// Bind the Siosis texture.
		
		static float ZP = 0.0f;
		ZP += 0.001f;
		glColor3f(ZP,ZP,ZP);
		glTranslatef(0,0,+(ZP*2));
		glBegin(GL_QUADS);
			glTexCoord2f(1.0f,0.0f); glVertex3f(1.0f,-1.0f,-6.0f);
			glTexCoord2f(0.0f,0.0f);glVertex3f(-1.0f,-1.0f,-6.0f);
			glTexCoord2f(0.0f,1.0f);glVertex3f(-1.0f,1.0f,-6.0f);
			glTexCoord2f(1.0f,1.0f);glVertex3f(1.0f,1.0f,-6.0f);
		glEnd();
			
		
		for(int ti=0;ti<MAX_SHARDS;ti++) 
		{
			shards[ti].Draw();	// Draw all 100 shards.
			shards[ti].Rot(); // For rotation.
		}
		SwapBuffers(hDC);
	}
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	SwapBuffers(hDC);
	//Pause(1);
	BASS_Stop();
	return 0;
}

#endif